#include "GlobalManage.h"

#include <QSettings>
#include <QCoreApplication>
#include <QTextCodec>

GlobalManage::GlobalManage()
{
    ConfigName = "Config.ini";
}

GlobalManage::~GlobalManage()
{

}

void GlobalManage::ReadConfigurationFile()
{
    QString fileName = QCoreApplication::applicationDirPath() + "/" + ConfigName;
    QSettings *setting = new QSettings(fileName , QSettings::IniFormat);
    setting->setIniCodec(QTextCodec::codecForName("UTF-8"));

    setting->beginGroup("MAP");

    m_MapFilePath = setting->value("MapFilePath","").toString();
    m_ZoomLevel = setting->value("ZoomLevel","").toFloat();

    double CenterOn_Lat,CenterOn_Lon;
    CenterOn_Lat = setting->value("CenterOn_Lat","").toDouble();
    CenterOn_Lon = setting->value("CenterOn_Lon","").toDouble();
    m_CenterOn = QGeoCoordinate(CenterOn_Lat,CenterOn_Lon

                                );

    setting->endGroup();

    delete setting;
}

void GlobalManage::WriteConfigurationFile()
{
    QString fileName = QCoreApplication::applicationDirPath() + "/" + ConfigName;
    QSettings *setting = new QSettings(fileName , QSettings::IniFormat);
    setting->setIniCodec(QTextCodec::codecForName("UTF-8"));

    setting->beginGroup("MAP");
    setting->setValue("MapFilePath",m_MapFilePath);

    setting->setValue("ZoomLevel",QString::number(m_ZoomLevel));

    setting->setValue("CenterOn_Lat",QString::number(m_CenterOn.latitude()));
    setting->setValue("CenterOn_Lon",QString::number(m_CenterOn.longitude()));

    setting->endGroup();

    delete setting;
}
